import java.io.*;
import java.util.Scanner;

/**
 * Creater with IntelliJ IDEA.
 * Description:
 * User: 86152
 * Dae: 2022-08-03
 * Time: 9:48
 */
public class demo2 {
    public static void main(String[] args) throws IOException {
        System.out.println("请输入文件路径");
        Scanner scanner = new Scanner(System.in);
        String sourcePath = scanner.next();
        File sourceFile = new File(sourcePath);
        if(!sourceFile.exists()) {
            System.out.println("该文件不存在");
            return;
        }
        if(sourceFile.isDirectory()) {
            System.out.println("该文件不是普通文件，请重新输入");
            return;
        }
        System.out.println("请输入要复制到的路径");
        String desPath = scanner.next();
        File desFile = new File(desPath);
        if(desFile.exists()) {
            if(desFile.isDirectory()) {
                System.out.println("目标路径已存在，并且是一个目录");
                return;
            } else {
                System.out.println("该文件已存在，是否覆盖(Y/N)");
                String choice = scanner.next();
                if(choice.compareTo("N")==0) {
                    System.out.println("停止复制");
                    return;
                }
            }
        }
        InputStream in = new FileInputStream(sourceFile);
        OutputStream os = new FileOutputStream(desFile);
        //复制内容
        byte[] tem = new byte[1024];
        int c;
        while(true) {
            c = in.read(tem);
            if(c==-1) {
                break;
            }
            os.write(tem);
        }
        os.flush();
    }
}
